package com.example.yuejian21.nongfusanquan.yuejian21.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.activity.ClubdetailActivtiy;
import com.squareup.picasso.Picasso;

import java.util.List;


import com.example.yuejian21.nongfusanquan.yuejian21.javabean.UserCollectclubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.R;

/**
 * Created by 皮金 on 2017/10/31.
 */

public class UsercollectAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public UsercollectAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_collectclub, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        final UserCollectclubbean entity = (UserCollectclubbean) mDataList.get(position);
        if (null == entity)
            return;


        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.club_name.setText(entity.getC_name());

        final String t_picture = "http://10.0.2.2/yuejian14/Public/Admin/clubphoto/" + entity.getC_pic();
        if (!t_picture.equals("")) {
            Picasso.with(mContex).load(t_picture).into(viewHolder.club_photo);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("c_id",entity.getC_id());
                bundle.putString("c_name",entity.getC_name());
                bundle.putString("c_time",entity.getC_time());
                bundle.putString("c_info",entity.getC_info());
                bundle.putString("c_phone",entity.getC_phone());
                bundle.putString("c_pic",entity.getC_pic());
                Intent intent=new Intent(mContex,ClubdetailActivtiy.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {return mDataList.size();}

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView club_photo;
        TextView club_name;
        public ViewHolder(View itemView) {
            super(itemView);
            club_photo = (ImageView) itemView.findViewById(R.id.collect_club_photo);
            club_name = (TextView) itemView.findViewById(R.id.collect_club_name);
        }
    }
}
